﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ConstructionPanel : OptionBasePanel
{
    public Image preShow;
    public Texture2D texStone,texArcher;
    public override void OnEnter()
    {
        base.OnEnter();
        preShow.color = new Color(1, 1, 1, 0);
        Vector2 texSize = new Vector2(ViewController.Instance.DistanceToScreen(ConstOfMap.xGap)/2, ViewController.Instance.DistanceToScreen(ConstOfMap.yGap)/2);
        preShow.GetComponent<RectTransform>().sizeDelta = texSize;
    }

    protected override void DoLeftOption()
    {
        base.DoLeftOption();
        if (!construction(BuildingType.BaseCrossbow))
            return;
        UIManager.Instance.PopPanel();
    }

    protected override void DoRightOption()
    {
        base.DoRightOption();
        if (!construction(BuildingType.BaseCannon))
            return;
        UIManager.Instance.PopPanel();
    }

    protected override void DoUpOption()
    {
        base.DoUpOption();
        //TODO 打开辅助建筑菜单
        UIManager.Instance.PushPanel("SupportMenuPanel",gameObject.transform.position);
    }

    protected override void DoDownOption()
    {
        base.DoDownOption();
        //TODO 打开陷阱菜单
        UIManager.Instance.PushPanel("TrapMenuPanel", gameObject.transform.position);
    }

    protected override void UpOptionStatus()
    {
        base.UpOptionStatus();
        preShow.color = new Color(1, 1, 1, 0);
        ViewableRange.Instance.ChangeTarget(null);
    }

    protected override void DownOptionStatus()
    {
        base.DownOptionStatus();
        preShow.color = new Color(1, 1, 1, 0);
        ViewableRange.Instance.ChangeTarget(null);
    }

    protected override void RightOptionStatus()
    {
        base.RightOptionStatus();
        ViewableRange.Instance.ChangeTarget(gameObject, 4.5f);
        preShow.sprite = Sprite.Create(texStone, new Rect(0, 0, texStone.width, texStone.height), new Vector2(0.5f, 0.5f));
        preShow.color = new Color(1, 1, 1, 0.5f);
    }

    protected override void LeftOptionStatus()
    {
        base.LeftOptionStatus();
        ViewableRange.Instance.ChangeTarget(gameObject, 3.5f);
        preShow.sprite = Sprite.Create(texArcher, new Rect(0, 0, texArcher.width, texArcher.height), new Vector2(0.5f, 0.5f));
        preShow.color = new Color(1, 1, 1, 0.5f);
    }

    protected override void InnerOptionStatus()
    {
        base.InnerOptionStatus();
        preShow.color = new Color(1, 1, 1, 0);
        ViewableRange.Instance.ChangeTarget(null);
    }

    protected override void setCostText()
    {
        up1.text = "";
        up2.text = "";
        down1.text = "";
        down2.text = "";
        right1.text = "AP:"+BuildingManager.Instance.GetRequiredAP(BuildingType.BaseCannon);
        right2.text = "G:" + BuildingManager.Instance.GetRequiredCost(BuildingType.BaseCannon);
        left1.text = "AP:" + BuildingManager.Instance.GetRequiredAP(BuildingType.BaseCrossbow);
        left2.text = "G:" + BuildingManager.Instance.GetRequiredCost(BuildingType.BaseCrossbow);
    }
}
